package com.ruoyi.web.controller.dir;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dir.domain.DirVersion;
import com.ruoyi.dir.service.IDirVersionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务目录版本Controller
 * 
 * @author ruoyi
 * @date 2025-11-1
 */
@Controller
@RequestMapping("/dir/version")
public class DirVersionController extends BaseController
{
    private String prefix = "dir/version";

    @Autowired
    private IDirVersionService dirVersionService;

    @RequiresPermissions("dir:version:view")
    @GetMapping()
    public String version()
    {
        return prefix + "/version";
    }

    /**
     * 查询服务目录版本列表
     */
    @RequiresPermissions("dir:version:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DirVersion dirVersion)
    {
        startPage();
        List<DirVersion> list = dirVersionService.selectDirVersionList(dirVersion);
        return getDataTable(list);
    }

    /**
     * 导出服务目录版本列表
     */
    @RequiresPermissions("dir:version:export")
    @Log(title = "服务目录版本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DirVersion dirVersion)
    {
        List<DirVersion> list = dirVersionService.selectDirVersionList(dirVersion);
        ExcelUtil<DirVersion> util = new ExcelUtil<DirVersion>(DirVersion.class);
        return util.exportExcel(list, "服务目录版本数据");
    }

    /**
     * 新增服务目录版本
     */
    @RequiresPermissions("dir:version:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存服务目录版本
     */
    @RequiresPermissions("dir:version:add")
    @Log(title = "服务目录版本", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DirVersion dirVersion)
    {
        return toAjax(dirVersionService.insertDirVersion(dirVersion));
    }

    /**
     * 修改服务目录版本
     */
    @RequiresPermissions("dir:version:edit")
    @GetMapping("/edit/{versionId}")
    public String edit(@PathVariable("versionId") Long versionId, ModelMap mmap)
    {
        DirVersion dirVersion = dirVersionService.selectDirVersionByVersionId(versionId);
        mmap.put("dirVersion", dirVersion);
        return prefix + "/edit";
    }

    /**
     * 修改保存服务目录版本
     */
    @RequiresPermissions("dir:version:edit")
    @Log(title = "服务目录版本", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DirVersion dirVersion)
    {
        return toAjax(dirVersionService.updateDirVersion(dirVersion));
    }

    /**
     * 删除服务目录版本
     */
    @RequiresPermissions("dir:version:remove")
    @Log(title = "服务目录版本", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dirVersionService.deleteDirVersionByVersionIds(ids));
    }
}
